<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //Promise.all()关注多个Promise对象的状态变化
        //传入多个Promise实例，包装成一个新的Promise实例返回值

        const delay = ms => {
            return new Promise(resolve => {
                setTimeout(resolve, ms)
            })
        }

        const p1 = delay(1000).then(() => {
            console.log('p1完成了');
            // return 'p1'
            return Promise.reject('reason')
        })

        const p2 = delay(2000).then(() => {
            console.log('p2完成了');
            //  return 'p2'
            return Promise.reject('reason')
        })

        const p = Promise.all([p1, p2]);
        p.then(data => {
            console.log(data);
        }, err => {
            console.log(err);
        })

        //promise.all()的状态变化与所有传入的Promise实例对象状态有关
        //所有状态变成resolved 最终的状态才会变成resolved
        //只要有一个状态变成rejected最终的状态才会变成rejected
    </script>
</body>

</html>